﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test.TestCusTomControl {
    public partial class TestTreeViewForm : Form
    {
        public TestTreeViewForm() {
            InitializeComponent();

            TreeNode node1 = treeView1.Nodes.Add("First Node");
            for (int i = 0; i < 10; i++)
            {
                node1.Nodes.Add("Level two node");                
            }

            TreeNode node2 = treeView1.Nodes.Add("Second Node");
            for (int i = 0; i < 20; i++) {
                node2.Nodes.Add("Level two node");
            }

            TreeNode node3 = treeView1.Nodes.Add("Third Node");
            for (int i = 0; i < 30; i++) {
                node3.Nodes.Add("Level two node");
            }
        }

        /// <summary>
        /// 折叠节点后更新滚动条长度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterCollapse(object sender, TreeViewEventArgs e) {
            this.treeViewVScrollBar1.UpdateSlidebar();
        }

        /// <summary>
        /// 展开节点后更新滚动条长度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterExpand(object sender, TreeViewEventArgs e) {
            this.treeViewVScrollBar1.UpdateSlidebar();
        }
    }
}
